<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet"  type="text/css"  href="/lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/custom.css">
    <link rel="stylesheet" href="/css/iosOverlay.css">
    <link rel="stylesheet" href="/css/prettify.css">
    <script src="/lib/plug/modernizr-2.0.6.min.js"></script>
    <link rel="stylesheet"  type="text/css" href="/css/orderhandle.css">
    <link rel="stylesheet" type="text/css" href="/css/layer.css">
    <style>
        input.active, textarea.active{
            border: 1px solid #e92300;
        }
        body{
            overflow-x: hidden;
        }
    </style>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-heading"><span style="font-weight: 600">订单编号1:</span ><i>{$orders[0]['order_number']}</i><span >下单时间</span><i>{$orders[0]['create_time']}</i></div>
    <div class="panel-body">
        <form action="">
        <div class="row ">
            <div class="col-sm-3">
                <div class="panel panel-default userdesc">
                    <div class="panel-heading">订单信息</div>
                    <div class="panel-body userdesc">
                        <div><span>收货人 &nbsp;&nbsp;：</span><span class="desc">{$orders[0]['buyer_name']}</span></div>
                        <div><span>手机号码：</span><input class="desc" type="text" name="phoneNum" disabled value="{$orders[0]['buyer_phone']}"></div>
                        <div><span>付款方式：</span>
                            {if condition="$orders[0]['pay_staff'] eq 1"}
                            <span class="desc"> 银行卡 </span>
                            {elseif condition="$orders[0]['pay_staff'] eq 2"}
                            <span class="desc"> 支付宝 </span>
                            {elseif condition="$orders[0]['pay_staff'] eq 3"}
                            <span class="desc"> 微信 </span>
                            {else /}
                            <span class="desc"> 未支付 </span>
                            {/if}
                       </div>
                        <div><span>付款账号：</span><span class="desc">{$orders[0]['pay_number']}</span></div>
                        <div><span>付款时间：</span><span class="desc">{$orders[0]['pay_time']|date="Y-m-d h:i:s",###}</span></div>
                        <div><span style="vertical-align: top;margin-top: 10px">收货地址:</span>
                            <textarea disabled name=""   cols="25" rows="5" class="desc" >{$orders[0]['order_addr']}</textarea></div>
                        <div class="update-order" style="text-align: right;margin-top: 20px;margin-right: 5px">
                            <button class="btn btn-default btn-sm" type="button" id="updateOrderBtn">修改信息</button><button class="btn  btn-sm" disabled id="complete" type="button">完成</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-9 ">
                <table class="table "style="text-align: center;border: 1px solid #BBBBBB">
                    <thead style="border: 1px solid #BBBBBB;background-color:#eeeeee;" >
                        <tr style="border-bottom: 1px solid #BBBBBB">
                            <td>商品名称</td>
                            <td>购买数量</td>
                            <td>单价</td>
                            <td>配送方式</td>
                            <!--<td>配送费</td>-->
                            <td>金额小计</td>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $shops as $shop}
                        <tr>
                            <td>
                                <img src="{$shop['image_path']}" style="display: block;width: 50px;height: 50px;margin: 0 auto" >
                                <p class="good-brand">编号：<i>010-A-b</i></p>
                                <p class="good-name">商品名：{$shop['shop_name']}</p>
                            </td>
                            <td>{$shop['shop_num']}</td>
                            <td class="price">
                               ¥<i>{$shop['shop_price']}</i>
                            </td>
                            <td>
                                中通快递
                            </td>
                            <!--<td class="price">-->
                                <!--¥<i>{$shop['freight']}</i>-->
                            <!--</td>-->
                            <td class="price">
                                ¥<i>{$shop['shop_total']}</i>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                <div class="pull-right pay">
                    <p>商品总金额: ¥<i>{$all['goods_total']}</i> （共<i>{$all['goods_num']}件）</i></span> &nbsp;<span>配送费: <i>¥{$shop['freight']}</i></span></p>
                    <p >订单总金额:¥<i>{$orders[0]['order_money']}</i></p>
                    <span >买家留言：</span><span class="leavebox">{$orders[0]['buyer_message']}</span>
                </div>
            </div>
        </div>
        <div class="row footer" >
            <div class="col-sm-6">
                <button type="button"  class="btn btn-danger" id="InvalidOrders" >无效订单</button>
            </div>
            <div class="col-sm-6 rightbtn">
                <button type="button"  class="btn btn-info" data-toggle="modal" data-target="#myModal">确认通过,开始填写物流信息</button>
            </div>
        </div>
        </form>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
    <form action="{:url('admin/order/logisticsAdd')}" method="post">
        <input type="text" hidden name="orderNum" value="{$orders[0]['order_number']}">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">填写物流单</h4>
            </div>
            <div class="modal-body">
                    <div class="form-group">
                        <label for="logistics" class="control-label">物流方式:</label>
                        <select  id="logistics" name="send_mode" class="form-control" style="width: 300px;height: 32px; border-radius:4px;display: inline-block;margin-left: 30px; text-align: center;border: 1px solid #ccc">
                            <option value="中通快递">中通快递</option>
                            <option value="韵达快递">韵达快递</option>
                            <option value="申通快递">申通快递</option>
                        </select>
                    </div>
                <div class="form-group">
                    <label for="logistics-number" class="control-label">物流单号:</label>
                    <input type="text" class="form-control" id="logistics-number" name="logistics_num" style="width: 300px; margin-left: 30px;display: inline-block">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">再确认一下订单信息</button>
                <button type="button" class="btn btn-primary" id="deliverBtn">订单无误，开始发货</button>
            </div>
        </div>
    </div>
    </form>
</div>
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/js/method.js"></script>
<script src="/lib/bootstrap/js/bootstrap.min.js"></script>
<script src="/js/iosOverlay.js"></script>
<script src="/lib/plug/spin.min.js"></script>
<script src="/lib/plug/prettify.js"></script>
<script src="/js/orderhandle.js"></script>
<script>
    var oldPhonenum=null;
    var oldAddress=null;
    $("#updateOrderBtn").click(function () {
        $("input[name=phoneNum]").attr("disabled",false).addClass("active");
        oldPhonenum=$("input[name=phoneNum]").val();
        $("textarea").attr("disabled",false).addClass("active");
        $("#complete").attr("disabled",false).addClass("btn-danger");
        oldAddress=$("textarea").val();
    });
    /*确认通过开始发货*/
    $("#deliverBtn").click(function () {
        var order_number=$("input[name=orderNum]").val();
        var logistics_number=$("#logistics-number").val();
        var send_mode=$("select[name=send_mode]").val();
        var expressage=$("select option:selected").val();
//        console.log(order_number,send_mode,logistics_number)
        if(logistics_number){
            $.ajax({
                url:"{:url('/admin/order/logisticsAdd')}",
                type:"post",
                data:{"order_number":order_number,"send_mode":send_mode,"logistics_num":logistics_number},
                async:false,
                dataType:"json",
                success:function (val) {
                    val=eval(val);
//                    console.log(val);
                    if(val.code==200){
                        $("#myModal").modal("hide")
                        iosOverlay({
                            text: "发货成功!",
                            duration: 2e3,
                            icon: "/images/check.png"
                        });
                    }else{
                        iosOverlay({
                            text: "操作失败，请联系客服!",
                            duration: 2e3,
                            icon: "/images/cross.png"
                        });
                    }
                }
            })
        }else{
            iosOverlay({
                text: "请填写物流单号!",
                duration: 2e3,
                icon: "/images/cross.png"
            });
        }
    });
    /*修改手机号和收货地址*/
    $("#complete").click(function () {
        var orderNum=$("input[name=orderNum]").val();
        var newPhonenum=$("input[name=phoneNum]").val();
        var newAddress=$("textarea").val();
        if(!/^\d{11}$/g.test(Number(newPhonenum))){
            iosOverlay({
                text: "手机号不正确!",
                duration: 2e3,
                icon: "/images/cross.png"
            });
            return
        }
        if(oldPhonenum !== newPhonenum || oldAddress !== newAddress){
           $.ajax({
               url:"{:url('admin/order/orderAddrUpdate')}",
               data:{"order_num":orderNum,"newphonenum":newPhonenum,"newAddress":newAddress},
               type:"post",
               async:false,
               dataType:"json",
               /*token: "csrftoken",*/
               success:function (val){
                  val=eval(val);
                  if(val.code==200){
                      iosOverlay({
                          text: "修改成功!",
                          duration: 2e3,
                          icon: "../../images/check.png"
                      });
                  }else if(val.code==100){
                      iosOverlay({
                          text: "修改失败!",
                          duration: 2e3,
                          icon: "../../images/cross.png"
                      });
                  }
                   $("input[name=phoneNum]").attr("disabled",false).removeClass("active");
                   $("textarea").attr("disabled",false).removeClass("active");
                   $("#complete").attr("disabled",true).removeClass("btn-danger");
               }
           })
        }else{
            $("input[name=phoneNum]").attr("disabled",true).removeClass("active");
            $("textarea").attr("disabled",true).removeClass("active");
            $("#complete").attr("disabled",true).removeClass("btn-danger");
        }
    });

    /*无效订单*/
    $("#InvalidOrders").click(function () {

        var obj={
            type:"showSweetAlert",
            close:"true",
            title:"",
            content:"<div>该订单已经支付，是否办理退款？</div>",
            btn:["取消","确定"],
            /*callBack1:function(){
                alert("已取消");
            },*/
            callBack2:function(){
                method.msg_layer({
                    title:"请选择退款方式",
                    btn:["一键退款","自定义折返"],
                    callBack1:function () {
                        var order_number=$("input[name=orderNum]").val();
                        $.ajax({
                            url:"{:url('admin/order/orderInvalid')}",
                            type:"post",
                            data:{"order_number":order_number},
                            dataType:"json",
                            async:false,
                            success:function (val) {
                            }})
                    },
                    callBack2:function () {
                        method.msg_layer({
                            title:"自定义退款",
                            btn:["取消","确定"],
                            content:`<form class="form-horizontal">
                          <div class="form-group">
                            <label  class="col-sm-4 control-label">收款人</label>
                            <div class="col-sm-8">
                              <input type="text" class="form-control" >
                            </div>
                          </div>
                          <div class="form-group">
                            <label  class="col-sm-4 control-label">收款账号</label>
                            <div class="col-sm-8">
                              <input type="text" class="form-control" >
                            </div>
                          </div>
                          <div class="form-group">
                            <label  class="col-sm-4 control-label">实退金额</label>
                            <div class="col-sm-8">
                              <input type="text" class="form-control"  placeholder="¥20.00">
                            </div>
                          </div>
                          <div class="form-group">
                            <label  class="col-sm-4 control-label">备注</label>
                            <div class="col-sm-8">
                              <textarea type="password" class="form-control" placeholder="请输入备注内容" >
                              </textarea>
                            </div>
                          </div>
                        </form>`,
                            callBack1:function () {

                            },
                            callBack2:function () {

                            }
                        })
                        }
                    })
            }
        };
        method.msg_layer(obj)
     /*   if (confirm("该订单已支付，是否办理退款？")){
            $.ajax({
                url:"{:url('admin/order/orderInvalid')}",
                type:"post",
                data:{"order_number":order_number},
                dataType:"json",
                async:false,
                success:function (val) {
                    console.log(val)
                }
            });
            return false
        }*/
    });



</script>
</body>
</html>